package config

import (
	"path/filepath"
	"sync"

	"github.com/BurntSushi/toml"
)

type tomlConfig struct {
	Tc tcConfig
}

type tcConfig struct {
	AccessKeyId string
	AccessKeySecret string
	Domain string
	DomainId *uint64
	SubDomain string
	RecordType string
	RecordLine string
	RecordLineId *uint64
	Value string
	TTL *uint64
	RecordId *uint64
}

var cfg *tomlConfig
var once sync.Once

func Config(path string) *tomlConfig {
	once.Do(func() {
		filePath, err := filepath.Abs(path)
		if err != nil {
			panic(err)
		}
		if _, err := toml.DecodeFile(filePath, &cfg); err != nil {
			panic(err)
		}
	})
	return cfg
}
